package com.insigma.yanwenlong.bookkeeping.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.insigma.yanwenlong.bookkeeping.db.jdbc.DBConnection;
import com.insigma.yanwenlong.bookkeeping.pojo.YearConsume;


public class YearConsumeDaoImpl implements YearConsumeDao {
    
	@Override
	public List<YearConsume> findAllYearConsume() throws SQLException {
		Connection connection = DBConnection.getConnection();
		String sql = "select * from yearconsumeview";
		Statement statement = connection.createStatement();
		ResultSet resultSet = statement.executeQuery(sql);
		
		List<YearConsume> yearConsumes = new ArrayList<YearConsume>();
		while(resultSet.next()) {
			YearConsume yearConsume = new YearConsume();
			
			yearConsume.setCategoryId(resultSet.getInt("categoryId"));
			yearConsume.setMonth1(resultSet.getDouble("month1"));
			yearConsume.setMonth2(resultSet.getDouble("month2"));
			yearConsume.setMonth3(resultSet.getDouble("month3"));
			yearConsume.setMonth4(resultSet.getDouble("month4"));
			yearConsume.setMonth5(resultSet.getDouble("month5"));
			yearConsume.setMonth6(resultSet.getDouble("month6"));
			yearConsume.setMonth7(resultSet.getDouble("month7"));
			yearConsume.setMonth8(resultSet.getDouble("month8"));
			yearConsume.setMonth9(resultSet.getDouble("month9"));
			yearConsume.setMonth10(resultSet.getDouble("month10"));
			yearConsume.setMonth11(resultSet.getDouble("month11"));
			yearConsume.setMonth12(resultSet.getDouble("month12"));
			
			yearConsumes.add(yearConsume);
		}
		
		DBConnection.closeResultSet(resultSet);
		DBConnection.closeStatement(statement);
		DBConnection.closeConnection(connection);
		
		return yearConsumes;
		
	}

}
